// Licensed to Elasticsearch B.V under one or more agreements.
// Elasticsearch B.V licenses this file to you under the Apache 2.0 License.
// See the LICENSE file in the project root for more information.
//
// ███╗   ██╗ ██████╗ ████████╗██╗ ██████╗███████╗
// ████╗  ██║██╔═══██╗╚══██╔══╝██║██╔════╝██╔════╝
// ██╔██╗ ██║██║   ██║   ██║   ██║██║     █████╗
// ██║╚██╗██║██║   ██║   ██║   ██║██║     ██╔══╝
// ██║ ╚████║╚██████╔╝   ██║   ██║╚██████╗███████╗
// ╚═╝  ╚═══╝ ╚═════╝    ╚═╝   ╚═╝ ╚═════╝╚══════╝
// ------------------------------------------------
//
// This file is automatically generated.
// Please do not edit these files manually.
//
// ------------------------------------------------

using Elastic.Transport;
using System;
using System.Collections.Generic;
using System.Linq.Expressions;
using System.Text.Json;
using System.Text.Json.Serialization;

#nullable restore
namespace Elastic.Clients.Elasticsearch.Ml
{
	public sealed class MlPutDatafeedRequestParameters : RequestParameters<MlPutDatafeedRequestParameters>
	{
		[JsonIgnore]
		public bool? AllowNoIndices { get => Q<bool?>("allow_no_indices"); set => Q("allow_no_indices", value); }

		[JsonIgnore]
		public IEnumerable<Elastic.Clients.Elasticsearch.ExpandWildcard>? ExpandWildcards { get => Q<IEnumerable<Elastic.Clients.Elasticsearch.ExpandWildcard>?>("expand_wildcards"); set => Q("expand_wildcards", value); }

		[JsonIgnore]
		public bool? IgnoreThrottled { get => Q<bool?>("ignore_throttled"); set => Q("ignore_throttled", value); }

		[JsonIgnore]
		public bool? IgnoreUnavailable { get => Q<bool?>("ignore_unavailable"); set => Q("ignore_unavailable", value); }
	}

	internal sealed class MlPutDatafeedRequestConverter : JsonConverter<MlPutDatafeedRequest>
	{
		public override MlPutDatafeedRequest Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
		{
			if (reader.TokenType != JsonTokenType.StartObject)
				throw new JsonException("Unexpected JSON detected.");
			var variant = new MlPutDatafeedRequest();
			while (reader.Read() && reader.TokenType != JsonTokenType.EndObject)
			{
				if (reader.TokenType == JsonTokenType.PropertyName)
				{
					var property = reader.GetString();
					if (property == "aggregations")
					{
						variant.Aggregations = JsonSerializer.Deserialize<Dictionary<string, Elastic.Clients.Elasticsearch.Aggregations.AggregationContainer>?>(ref reader, options);
						continue;
					}

					if (property == "chunking_config")
					{
						variant.ChunkingConfig = JsonSerializer.Deserialize<Elastic.Clients.Elasticsearch.Ml.ChunkingConfig?>(ref reader, options);
						continue;
					}

					if (property == "delayed_data_check_config")
					{
						variant.DelayedDataCheckConfig = JsonSerializer.Deserialize<Elastic.Clients.Elasticsearch.Ml.DelayedDataCheckConfig?>(ref reader, options);
						continue;
					}

					if (property == "frequency")
					{
						variant.Frequency = JsonSerializer.Deserialize<Elastic.Clients.Elasticsearch.Duration?>(ref reader, options);
						continue;
					}

					if (property == "indices" || property == "indexes")
					{
						variant.Indices = JsonSerializer.Deserialize<Elastic.Clients.Elasticsearch.Indices?>(ref reader, options);
						continue;
					}

					if (property == "indices_options")
					{
						variant.IndicesOptions = JsonSerializer.Deserialize<Elastic.Clients.Elasticsearch.IndicesOptions?>(ref reader, options);
						continue;
					}

					if (property == "job_id")
					{
						variant.JobId = JsonSerializer.Deserialize<Elastic.Clients.Elasticsearch.Id?>(ref reader, options);
						continue;
					}

					if (property == "max_empty_searches")
					{
						variant.MaxEmptySearches = JsonSerializer.Deserialize<int?>(ref reader, options);
						continue;
					}

					if (property == "query")
					{
						variant.Query = JsonSerializer.Deserialize<Elastic.Clients.Elasticsearch.QueryDsl.QueryContainer?>(ref reader, options);
						continue;
					}

					if (property == "query_delay")
					{
						variant.QueryDelay = JsonSerializer.Deserialize<Elastic.Clients.Elasticsearch.Duration?>(ref reader, options);
						continue;
					}

					if (property == "runtime_mappings")
					{
						variant.RuntimeMappings = JsonSerializer.Deserialize<Dictionary<Elastic.Clients.Elasticsearch.Field, IEnumerable<Elastic.Clients.Elasticsearch.Mapping.RuntimeField>>?>(ref reader, options);
						continue;
					}

					if (property == "script_fields")
					{
						variant.ScriptFields = JsonSerializer.Deserialize<Dictionary<string, Elastic.Clients.Elasticsearch.ScriptField>?>(ref reader, options);
						continue;
					}

					if (property == "scroll_size")
					{
						variant.ScrollSize = JsonSerializer.Deserialize<int?>(ref reader, options);
						continue;
					}

					if (property == "headers")
					{
						variant.Headers = JsonSerializer.Deserialize<Dictionary<string, IEnumerable<string>>?>(ref reader, options);
						continue;
					}
				}
			}

			return variant;
		}

		public override void Write(Utf8JsonWriter writer, MlPutDatafeedRequest value, JsonSerializerOptions options)
		{
			writer.WriteStartObject();
			if (value.Aggregations is not null)
			{
				writer.WritePropertyName("aggregations");
				JsonSerializer.Serialize(writer, value.Aggregations, options);
			}

			if (value.ChunkingConfig is not null)
			{
				writer.WritePropertyName("chunking_config");
				JsonSerializer.Serialize(writer, value.ChunkingConfig, options);
			}

			if (value.DelayedDataCheckConfig is not null)
			{
				writer.WritePropertyName("delayed_data_check_config");
				JsonSerializer.Serialize(writer, value.DelayedDataCheckConfig, options);
			}

			if (value.Frequency is not null)
			{
				writer.WritePropertyName("frequency");
				JsonSerializer.Serialize(writer, value.Frequency, options);
			}

			if (value.Indices is not null)
			{
				writer.WritePropertyName("indices");
				JsonSerializer.Serialize(writer, value.Indices, options);
			}

			if (value.IndicesOptions is not null)
			{
				writer.WritePropertyName("indices_options");
				JsonSerializer.Serialize(writer, value.IndicesOptions, options);
			}

			if (value.JobId is not null)
			{
				writer.WritePropertyName("job_id");
				JsonSerializer.Serialize(writer, value.JobId, options);
			}

			if (value.MaxEmptySearches.HasValue)
			{
				writer.WritePropertyName("max_empty_searches");
				writer.WriteNumberValue(value.MaxEmptySearches.Value);
			}

			if (value.Query is not null)
			{
				writer.WritePropertyName("query");
				JsonSerializer.Serialize(writer, value.Query, options);
			}

			if (value.QueryDelay is not null)
			{
				writer.WritePropertyName("query_delay");
				JsonSerializer.Serialize(writer, value.QueryDelay, options);
			}

			if (value.RuntimeMappings is not null)
			{
				writer.WritePropertyName("runtime_mappings");
				JsonSerializer.Serialize(writer, value.RuntimeMappings, options);
			}

			if (value.ScriptFields is not null)
			{
				writer.WritePropertyName("script_fields");
				JsonSerializer.Serialize(writer, value.ScriptFields, options);
			}

			if (value.ScrollSize.HasValue)
			{
				writer.WritePropertyName("scroll_size");
				writer.WriteNumberValue(value.ScrollSize.Value);
			}

			if (value.Headers is not null)
			{
				writer.WritePropertyName("headers");
				JsonSerializer.Serialize(writer, value.Headers, options);
			}

			writer.WriteEndObject();
		}
	}

	[JsonConverter(typeof(MlPutDatafeedRequestConverter))]
	public sealed partial class MlPutDatafeedRequest : PlainRequestBase<MlPutDatafeedRequestParameters>
	{
		public MlPutDatafeedRequest(Elastic.Clients.Elasticsearch.Id datafeed_id) : base(r => r.Required("datafeed_id", datafeed_id))
		{
		}

		internal MlPutDatafeedRequest()
		{
		}

		internal override ApiUrls ApiUrls => ApiUrlsLookups.MachineLearningPutDatafeed;
		protected override HttpMethod HttpMethod => HttpMethod.PUT;
		protected override bool SupportsBody => true;
		[JsonIgnore]
		public bool? AllowNoIndices { get => Q<bool?>("allow_no_indices"); set => Q("allow_no_indices", value); }

		[JsonIgnore]
		public IEnumerable<Elastic.Clients.Elasticsearch.ExpandWildcard>? ExpandWildcards { get => Q<IEnumerable<Elastic.Clients.Elasticsearch.ExpandWildcard>?>("expand_wildcards"); set => Q("expand_wildcards", value); }

		[JsonIgnore]
		public bool? IgnoreThrottled { get => Q<bool?>("ignore_throttled"); set => Q("ignore_throttled", value); }

		[JsonIgnore]
		public bool? IgnoreUnavailable { get => Q<bool?>("ignore_unavailable"); set => Q("ignore_unavailable", value); }

		[JsonInclude]
		[JsonPropertyName("aggregations")]
		public Dictionary<string, Elastic.Clients.Elasticsearch.Aggregations.AggregationContainer>? Aggregations { get; set; }

		[JsonInclude]
		[JsonPropertyName("chunking_config")]
		public Elastic.Clients.Elasticsearch.Ml.ChunkingConfig? ChunkingConfig { get; set; }

		[JsonInclude]
		[JsonPropertyName("delayed_data_check_config")]
		public Elastic.Clients.Elasticsearch.Ml.DelayedDataCheckConfig? DelayedDataCheckConfig { get; set; }

		[JsonInclude]
		[JsonPropertyName("frequency")]
		public Elastic.Clients.Elasticsearch.Duration? Frequency { get; set; }

		[JsonInclude]
		[JsonPropertyName("indices")]
		public Elastic.Clients.Elasticsearch.Indices? Indices { get; set; }

		[JsonInclude]
		[JsonPropertyName("indices_options")]
		public Elastic.Clients.Elasticsearch.IndicesOptions? IndicesOptions { get; set; }

		[JsonInclude]
		[JsonPropertyName("job_id")]
		public Elastic.Clients.Elasticsearch.Id? JobId { get; set; }

		[JsonInclude]
		[JsonPropertyName("max_empty_searches")]
		public int? MaxEmptySearches { get; set; }

		[JsonInclude]
		[JsonPropertyName("query")]
		public Elastic.Clients.Elasticsearch.QueryDsl.QueryContainer? Query { get; set; }

		[JsonInclude]
		[JsonPropertyName("query_delay")]
		public Elastic.Clients.Elasticsearch.Duration? QueryDelay { get; set; }

		[JsonInclude]
		[JsonPropertyName("runtime_mappings")]
		public Dictionary<Elastic.Clients.Elasticsearch.Field, IEnumerable<Elastic.Clients.Elasticsearch.Mapping.RuntimeField>>? RuntimeMappings { get; set; }

		[JsonInclude]
		[JsonPropertyName("script_fields")]
		public Dictionary<string, Elastic.Clients.Elasticsearch.ScriptField>? ScriptFields { get; set; }

		[JsonInclude]
		[JsonPropertyName("scroll_size")]
		public int? ScrollSize { get; set; }

		[JsonInclude]
		[JsonPropertyName("headers")]
		public Dictionary<string, IEnumerable<string>>? Headers { get; set; }
	}

	public sealed partial class MlPutDatafeedRequestDescriptor<TDocument> : RequestDescriptorBase<MlPutDatafeedRequestDescriptor<TDocument>, MlPutDatafeedRequestParameters>
	{
		internal MlPutDatafeedRequestDescriptor(Action<MlPutDatafeedRequestDescriptor<TDocument>> configure) => configure.Invoke(this);
		public MlPutDatafeedRequestDescriptor(Elastic.Clients.Elasticsearch.Id datafeed_id) : base(r => r.Required("datafeed_id", datafeed_id))
		{
		}

		internal MlPutDatafeedRequestDescriptor()
		{
		}

		internal override ApiUrls ApiUrls => ApiUrlsLookups.MachineLearningPutDatafeed;
		protected override HttpMethod HttpMethod => HttpMethod.PUT;
		protected override bool SupportsBody => true;
		public MlPutDatafeedRequestDescriptor<TDocument> AllowNoIndices(bool? allowNoIndices = true) => Qs("allow_no_indices", allowNoIndices);
		public MlPutDatafeedRequestDescriptor<TDocument> ExpandWildcards(IEnumerable<Elastic.Clients.Elasticsearch.ExpandWildcard>? expandWildcards) => Qs("expand_wildcards", expandWildcards);
		public MlPutDatafeedRequestDescriptor<TDocument> IgnoreThrottled(bool? ignoreThrottled = true) => Qs("ignore_throttled", ignoreThrottled);
		public MlPutDatafeedRequestDescriptor<TDocument> IgnoreUnavailable(bool? ignoreUnavailable = true) => Qs("ignore_unavailable", ignoreUnavailable);
		public MlPutDatafeedRequestDescriptor<TDocument> DatafeedId(Elastic.Clients.Elasticsearch.Id datafeed_id)
		{
			RouteValues.Required("datafeed_id", datafeed_id);
			return Self;
		}

		private Elastic.Clients.Elasticsearch.QueryDsl.QueryContainer? QueryValue { get; set; }

		private QueryDsl.QueryContainerDescriptor<TDocument> QueryDescriptor { get; set; }

		private Action<QueryDsl.QueryContainerDescriptor<TDocument>> QueryDescriptorAction { get; set; }

		private Dictionary<string, Elastic.Clients.Elasticsearch.Aggregations.AggregationContainer>? AggregationsValue { get; set; }

		private Elastic.Clients.Elasticsearch.Ml.ChunkingConfig? ChunkingConfigValue { get; set; }

		private ChunkingConfigDescriptor ChunkingConfigDescriptor { get; set; }

		private Action<ChunkingConfigDescriptor> ChunkingConfigDescriptorAction { get; set; }

		private Elastic.Clients.Elasticsearch.Ml.DelayedDataCheckConfig? DelayedDataCheckConfigValue { get; set; }

		private DelayedDataCheckConfigDescriptor DelayedDataCheckConfigDescriptor { get; set; }

		private Action<DelayedDataCheckConfigDescriptor> DelayedDataCheckConfigDescriptorAction { get; set; }

		private Elastic.Clients.Elasticsearch.Duration? FrequencyValue { get; set; }

		private Dictionary<string, IEnumerable<string>>? HeadersValue { get; set; }

		private Elastic.Clients.Elasticsearch.Indices? IndicesValue { get; set; }

		private Elastic.Clients.Elasticsearch.IndicesOptions? IndicesOptionsValue { get; set; }

		private IndicesOptionsDescriptor IndicesOptionsDescriptor { get; set; }

		private Action<IndicesOptionsDescriptor> IndicesOptionsDescriptorAction { get; set; }

		private Elastic.Clients.Elasticsearch.Id? JobIdValue { get; set; }

		private int? MaxEmptySearchesValue { get; set; }

		private Elastic.Clients.Elasticsearch.Duration? QueryDelayValue { get; set; }

		private Dictionary<Elastic.Clients.Elasticsearch.Field, IEnumerable<Elastic.Clients.Elasticsearch.Mapping.RuntimeField>>? RuntimeMappingsValue { get; set; }

		private Dictionary<string, Elastic.Clients.Elasticsearch.ScriptField>? ScriptFieldsValue { get; set; }

		private int? ScrollSizeValue { get; set; }

		public MlPutDatafeedRequestDescriptor<TDocument> Query(Elastic.Clients.Elasticsearch.QueryDsl.QueryContainer? query)
		{
			QueryDescriptor = null;
			QueryDescriptorAction = null;
			QueryValue = query;
			return Self;
		}

		public MlPutDatafeedRequestDescriptor<TDocument> Query(QueryDsl.QueryContainerDescriptor<TDocument> descriptor)
		{
			QueryValue = null;
			QueryDescriptorAction = null;
			QueryDescriptor = descriptor;
			return Self;
		}

		public MlPutDatafeedRequestDescriptor<TDocument> Query(Action<QueryDsl.QueryContainerDescriptor<TDocument>> configure)
		{
			QueryValue = null;
			QueryDescriptor = null;
			QueryDescriptorAction = configure;
			return Self;
		}

		public MlPutDatafeedRequestDescriptor<TDocument> Aggregations(Func<FluentDictionary<string, Elastic.Clients.Elasticsearch.Aggregations.AggregationContainer>, FluentDictionary<string, Elastic.Clients.Elasticsearch.Aggregations.AggregationContainer>> selector)
		{
			AggregationsValue = selector?.Invoke(new FluentDictionary<string, Elastic.Clients.Elasticsearch.Aggregations.AggregationContainer>());
			return Self;
		}

		public MlPutDatafeedRequestDescriptor<TDocument> ChunkingConfig(Elastic.Clients.Elasticsearch.Ml.ChunkingConfig? chunkingConfig)
		{
			ChunkingConfigDescriptor = null;
			ChunkingConfigDescriptorAction = null;
			ChunkingConfigValue = chunkingConfig;
			return Self;
		}

		public MlPutDatafeedRequestDescriptor<TDocument> ChunkingConfig(ChunkingConfigDescriptor descriptor)
		{
			ChunkingConfigValue = null;
			ChunkingConfigDescriptorAction = null;
			ChunkingConfigDescriptor = descriptor;
			return Self;
		}

		public MlPutDatafeedRequestDescriptor<TDocument> ChunkingConfig(Action<ChunkingConfigDescriptor> configure)
		{
			ChunkingConfigValue = null;
			ChunkingConfigDescriptor = null;
			ChunkingConfigDescriptorAction = configure;
			return Self;
		}

		public MlPutDatafeedRequestDescriptor<TDocument> DelayedDataCheckConfig(Elastic.Clients.Elasticsearch.Ml.DelayedDataCheckConfig? delayedDataCheckConfig)
		{
			DelayedDataCheckConfigDescriptor = null;
			DelayedDataCheckConfigDescriptorAction = null;
			DelayedDataCheckConfigValue = delayedDataCheckConfig;
			return Self;
		}

		public MlPutDatafeedRequestDescriptor<TDocument> DelayedDataCheckConfig(DelayedDataCheckConfigDescriptor descriptor)
		{
			DelayedDataCheckConfigValue = null;
			DelayedDataCheckConfigDescriptorAction = null;
			DelayedDataCheckConfigDescriptor = descriptor;
			return Self;
		}

		public MlPutDatafeedRequestDescriptor<TDocument> DelayedDataCheckConfig(Action<DelayedDataCheckConfigDescriptor> configure)
		{
			DelayedDataCheckConfigValue = null;
			DelayedDataCheckConfigDescriptor = null;
			DelayedDataCheckConfigDescriptorAction = configure;
			return Self;
		}

		public MlPutDatafeedRequestDescriptor<TDocument> Frequency(Elastic.Clients.Elasticsearch.Duration? frequency)
		{
			FrequencyValue = frequency;
			return Self;
		}

		public MlPutDatafeedRequestDescriptor<TDocument> Headers(Func<FluentDictionary<string, IEnumerable<string>>, FluentDictionary<string, IEnumerable<string>>> selector)
		{
			HeadersValue = selector?.Invoke(new FluentDictionary<string, IEnumerable<string>>());
			return Self;
		}

		public MlPutDatafeedRequestDescriptor<TDocument> Indices(Elastic.Clients.Elasticsearch.Indices? indices)
		{
			IndicesValue = indices;
			return Self;
		}

		public MlPutDatafeedRequestDescriptor<TDocument> IndicesOptions(Elastic.Clients.Elasticsearch.IndicesOptions? indicesOptions)
		{
			IndicesOptionsDescriptor = null;
			IndicesOptionsDescriptorAction = null;
			IndicesOptionsValue = indicesOptions;
			return Self;
		}

		public MlPutDatafeedRequestDescriptor<TDocument> IndicesOptions(IndicesOptionsDescriptor descriptor)
		{
			IndicesOptionsValue = null;
			IndicesOptionsDescriptorAction = null;
			IndicesOptionsDescriptor = descriptor;
			return Self;
		}

		public MlPutDatafeedRequestDescriptor<TDocument> IndicesOptions(Action<IndicesOptionsDescriptor> configure)
		{
			IndicesOptionsValue = null;
			IndicesOptionsDescriptor = null;
			IndicesOptionsDescriptorAction = configure;
			return Self;
		}

		public MlPutDatafeedRequestDescriptor<TDocument> JobId(Elastic.Clients.Elasticsearch.Id? jobId)
		{
			JobIdValue = jobId;
			return Self;
		}

		public MlPutDatafeedRequestDescriptor<TDocument> MaxEmptySearches(int? maxEmptySearches)
		{
			MaxEmptySearchesValue = maxEmptySearches;
			return Self;
		}

		public MlPutDatafeedRequestDescriptor<TDocument> QueryDelay(Elastic.Clients.Elasticsearch.Duration? queryDelay)
		{
			QueryDelayValue = queryDelay;
			return Self;
		}

		public MlPutDatafeedRequestDescriptor<TDocument> RuntimeMappings(Func<FluentDictionary<Elastic.Clients.Elasticsearch.Field, IEnumerable<Elastic.Clients.Elasticsearch.Mapping.RuntimeField>>, FluentDictionary<Elastic.Clients.Elasticsearch.Field, IEnumerable<Elastic.Clients.Elasticsearch.Mapping.RuntimeField>>> selector)
		{
			RuntimeMappingsValue = selector?.Invoke(new FluentDictionary<Elastic.Clients.Elasticsearch.Field, IEnumerable<Elastic.Clients.Elasticsearch.Mapping.RuntimeField>>());
			return Self;
		}

		public MlPutDatafeedRequestDescriptor<TDocument> ScriptFields(Func<FluentDictionary<string, Elastic.Clients.Elasticsearch.ScriptField>, FluentDictionary<string, Elastic.Clients.Elasticsearch.ScriptField>> selector)
		{
			ScriptFieldsValue = selector?.Invoke(new FluentDictionary<string, Elastic.Clients.Elasticsearch.ScriptField>());
			return Self;
		}

		public MlPutDatafeedRequestDescriptor<TDocument> ScrollSize(int? scrollSize)
		{
			ScrollSizeValue = scrollSize;
			return Self;
		}

		protected override void Serialize(Utf8JsonWriter writer, JsonSerializerOptions options, IElasticsearchClientSettings settings)
		{
			writer.WriteStartObject();
			if (QueryDescriptor is not null)
			{
				writer.WritePropertyName("query");
				JsonSerializer.Serialize(writer, QueryDescriptor, options);
			}
			else if (QueryDescriptorAction is not null)
			{
				writer.WritePropertyName("query");
				JsonSerializer.Serialize(writer, new QueryDsl.QueryContainerDescriptor<TDocument>(QueryDescriptorAction), options);
			}
			else if (QueryValue is not null)
			{
				writer.WritePropertyName("query");
				JsonSerializer.Serialize(writer, QueryValue, options);
			}

			if (AggregationsValue is not null)
			{
				writer.WritePropertyName("aggregations");
				JsonSerializer.Serialize(writer, AggregationsValue, options);
			}

			if (ChunkingConfigDescriptor is not null)
			{
				writer.WritePropertyName("chunking_config");
				JsonSerializer.Serialize(writer, ChunkingConfigDescriptor, options);
			}
			else if (ChunkingConfigDescriptorAction is not null)
			{
				writer.WritePropertyName("chunking_config");
				JsonSerializer.Serialize(writer, new ChunkingConfigDescriptor(ChunkingConfigDescriptorAction), options);
			}
			else if (ChunkingConfigValue is not null)
			{
				writer.WritePropertyName("chunking_config");
				JsonSerializer.Serialize(writer, ChunkingConfigValue, options);
			}

			if (DelayedDataCheckConfigDescriptor is not null)
			{
				writer.WritePropertyName("delayed_data_check_config");
				JsonSerializer.Serialize(writer, DelayedDataCheckConfigDescriptor, options);
			}
			else if (DelayedDataCheckConfigDescriptorAction is not null)
			{
				writer.WritePropertyName("delayed_data_check_config");
				JsonSerializer.Serialize(writer, new DelayedDataCheckConfigDescriptor(DelayedDataCheckConfigDescriptorAction), options);
			}
			else if (DelayedDataCheckConfigValue is not null)
			{
				writer.WritePropertyName("delayed_data_check_config");
				JsonSerializer.Serialize(writer, DelayedDataCheckConfigValue, options);
			}

			if (FrequencyValue is not null)
			{
				writer.WritePropertyName("frequency");
				JsonSerializer.Serialize(writer, FrequencyValue, options);
			}

			if (HeadersValue is not null)
			{
				writer.WritePropertyName("headers");
				JsonSerializer.Serialize(writer, HeadersValue, options);
			}

			if (IndicesValue is not null)
			{
				writer.WritePropertyName("indices");
				JsonSerializer.Serialize(writer, IndicesValue, options);
			}

			if (IndicesOptionsDescriptor is not null)
			{
				writer.WritePropertyName("indices_options");
				JsonSerializer.Serialize(writer, IndicesOptionsDescriptor, options);
			}
			else if (IndicesOptionsDescriptorAction is not null)
			{
				writer.WritePropertyName("indices_options");
				JsonSerializer.Serialize(writer, new IndicesOptionsDescriptor(IndicesOptionsDescriptorAction), options);
			}
			else if (IndicesOptionsValue is not null)
			{
				writer.WritePropertyName("indices_options");
				JsonSerializer.Serialize(writer, IndicesOptionsValue, options);
			}

			if (JobIdValue is not null)
			{
				writer.WritePropertyName("job_id");
				JsonSerializer.Serialize(writer, JobIdValue, options);
			}

			if (MaxEmptySearchesValue.HasValue)
			{
				writer.WritePropertyName("max_empty_searches");
				writer.WriteNumberValue(MaxEmptySearchesValue.Value);
			}

			if (QueryDelayValue is not null)
			{
				writer.WritePropertyName("query_delay");
				JsonSerializer.Serialize(writer, QueryDelayValue, options);
			}

			if (RuntimeMappingsValue is not null)
			{
				writer.WritePropertyName("runtime_mappings");
				JsonSerializer.Serialize(writer, RuntimeMappingsValue, options);
			}

			if (ScriptFieldsValue is not null)
			{
				writer.WritePropertyName("script_fields");
				JsonSerializer.Serialize(writer, ScriptFieldsValue, options);
			}

			if (ScrollSizeValue.HasValue)
			{
				writer.WritePropertyName("scroll_size");
				writer.WriteNumberValue(ScrollSizeValue.Value);
			}

			writer.WriteEndObject();
		}
	}

	public sealed partial class MlPutDatafeedRequestDescriptor : RequestDescriptorBase<MlPutDatafeedRequestDescriptor, MlPutDatafeedRequestParameters>
	{
		internal MlPutDatafeedRequestDescriptor(Action<MlPutDatafeedRequestDescriptor> configure) => configure.Invoke(this);
		public MlPutDatafeedRequestDescriptor(Elastic.Clients.Elasticsearch.Id datafeed_id) : base(r => r.Required("datafeed_id", datafeed_id))
		{
		}

		internal MlPutDatafeedRequestDescriptor()
		{
		}

		internal override ApiUrls ApiUrls => ApiUrlsLookups.MachineLearningPutDatafeed;
		protected override HttpMethod HttpMethod => HttpMethod.PUT;
		protected override bool SupportsBody => true;
		public MlPutDatafeedRequestDescriptor AllowNoIndices(bool? allowNoIndices = true) => Qs("allow_no_indices", allowNoIndices);
		public MlPutDatafeedRequestDescriptor ExpandWildcards(IEnumerable<Elastic.Clients.Elasticsearch.ExpandWildcard>? expandWildcards) => Qs("expand_wildcards", expandWildcards);
		public MlPutDatafeedRequestDescriptor IgnoreThrottled(bool? ignoreThrottled = true) => Qs("ignore_throttled", ignoreThrottled);
		public MlPutDatafeedRequestDescriptor IgnoreUnavailable(bool? ignoreUnavailable = true) => Qs("ignore_unavailable", ignoreUnavailable);
		public MlPutDatafeedRequestDescriptor DatafeedId(Elastic.Clients.Elasticsearch.Id datafeed_id)
		{
			RouteValues.Required("datafeed_id", datafeed_id);
			return Self;
		}

		private Elastic.Clients.Elasticsearch.QueryDsl.QueryContainer? QueryValue { get; set; }

		private QueryDsl.QueryContainerDescriptor QueryDescriptor { get; set; }

		private Action<QueryDsl.QueryContainerDescriptor> QueryDescriptorAction { get; set; }

		private Dictionary<string, Elastic.Clients.Elasticsearch.Aggregations.AggregationContainer>? AggregationsValue { get; set; }

		private Elastic.Clients.Elasticsearch.Ml.ChunkingConfig? ChunkingConfigValue { get; set; }

		private ChunkingConfigDescriptor ChunkingConfigDescriptor { get; set; }

		private Action<ChunkingConfigDescriptor> ChunkingConfigDescriptorAction { get; set; }

		private Elastic.Clients.Elasticsearch.Ml.DelayedDataCheckConfig? DelayedDataCheckConfigValue { get; set; }

		private DelayedDataCheckConfigDescriptor DelayedDataCheckConfigDescriptor { get; set; }

		private Action<DelayedDataCheckConfigDescriptor> DelayedDataCheckConfigDescriptorAction { get; set; }

		private Elastic.Clients.Elasticsearch.Duration? FrequencyValue { get; set; }

		private Dictionary<string, IEnumerable<string>>? HeadersValue { get; set; }

		private Elastic.Clients.Elasticsearch.Indices? IndicesValue { get; set; }

		private Elastic.Clients.Elasticsearch.IndicesOptions? IndicesOptionsValue { get; set; }

		private IndicesOptionsDescriptor IndicesOptionsDescriptor { get; set; }

		private Action<IndicesOptionsDescriptor> IndicesOptionsDescriptorAction { get; set; }

		private Elastic.Clients.Elasticsearch.Id? JobIdValue { get; set; }

		private int? MaxEmptySearchesValue { get; set; }

		private Elastic.Clients.Elasticsearch.Duration? QueryDelayValue { get; set; }

		private Dictionary<Elastic.Clients.Elasticsearch.Field, IEnumerable<Elastic.Clients.Elasticsearch.Mapping.RuntimeField>>? RuntimeMappingsValue { get; set; }

		private Dictionary<string, Elastic.Clients.Elasticsearch.ScriptField>? ScriptFieldsValue { get; set; }

		private int? ScrollSizeValue { get; set; }

		public MlPutDatafeedRequestDescriptor Query(Elastic.Clients.Elasticsearch.QueryDsl.QueryContainer? query)
		{
			QueryDescriptor = null;
			QueryDescriptorAction = null;
			QueryValue = query;
			return Self;
		}

		public MlPutDatafeedRequestDescriptor Query(QueryDsl.QueryContainerDescriptor descriptor)
		{
			QueryValue = null;
			QueryDescriptorAction = null;
			QueryDescriptor = descriptor;
			return Self;
		}

		public MlPutDatafeedRequestDescriptor Query(Action<QueryDsl.QueryContainerDescriptor> configure)
		{
			QueryValue = null;
			QueryDescriptor = null;
			QueryDescriptorAction = configure;
			return Self;
		}

		public MlPutDatafeedRequestDescriptor Aggregations(Func<FluentDictionary<string, Elastic.Clients.Elasticsearch.Aggregations.AggregationContainer>, FluentDictionary<string, Elastic.Clients.Elasticsearch.Aggregations.AggregationContainer>> selector)
		{
			AggregationsValue = selector?.Invoke(new FluentDictionary<string, Elastic.Clients.Elasticsearch.Aggregations.AggregationContainer>());
			return Self;
		}

		public MlPutDatafeedRequestDescriptor ChunkingConfig(Elastic.Clients.Elasticsearch.Ml.ChunkingConfig? chunkingConfig)
		{
			ChunkingConfigDescriptor = null;
			ChunkingConfigDescriptorAction = null;
			ChunkingConfigValue = chunkingConfig;
			return Self;
		}

		public MlPutDatafeedRequestDescriptor ChunkingConfig(ChunkingConfigDescriptor descriptor)
		{
			ChunkingConfigValue = null;
			ChunkingConfigDescriptorAction = null;
			ChunkingConfigDescriptor = descriptor;
			return Self;
		}

		public MlPutDatafeedRequestDescriptor ChunkingConfig(Action<ChunkingConfigDescriptor> configure)
		{
			ChunkingConfigValue = null;
			ChunkingConfigDescriptor = null;
			ChunkingConfigDescriptorAction = configure;
			return Self;
		}

		public MlPutDatafeedRequestDescriptor DelayedDataCheckConfig(Elastic.Clients.Elasticsearch.Ml.DelayedDataCheckConfig? delayedDataCheckConfig)
		{
			DelayedDataCheckConfigDescriptor = null;
			DelayedDataCheckConfigDescriptorAction = null;
			DelayedDataCheckConfigValue = delayedDataCheckConfig;
			return Self;
		}

		public MlPutDatafeedRequestDescriptor DelayedDataCheckConfig(DelayedDataCheckConfigDescriptor descriptor)
		{
			DelayedDataCheckConfigValue = null;
			DelayedDataCheckConfigDescriptorAction = null;
			DelayedDataCheckConfigDescriptor = descriptor;
			return Self;
		}

		public MlPutDatafeedRequestDescriptor DelayedDataCheckConfig(Action<DelayedDataCheckConfigDescriptor> configure)
		{
			DelayedDataCheckConfigValue = null;
			DelayedDataCheckConfigDescriptor = null;
			DelayedDataCheckConfigDescriptorAction = configure;
			return Self;
		}

		public MlPutDatafeedRequestDescriptor Frequency(Elastic.Clients.Elasticsearch.Duration? frequency)
		{
			FrequencyValue = frequency;
			return Self;
		}

		public MlPutDatafeedRequestDescriptor Headers(Func<FluentDictionary<string, IEnumerable<string>>, FluentDictionary<string, IEnumerable<string>>> selector)
		{
			HeadersValue = selector?.Invoke(new FluentDictionary<string, IEnumerable<string>>());
			return Self;
		}

		public MlPutDatafeedRequestDescriptor Indices(Elastic.Clients.Elasticsearch.Indices? indices)
		{
			IndicesValue = indices;
			return Self;
		}

		public MlPutDatafeedRequestDescriptor IndicesOptions(Elastic.Clients.Elasticsearch.IndicesOptions? indicesOptions)
		{
			IndicesOptionsDescriptor = null;
			IndicesOptionsDescriptorAction = null;
			IndicesOptionsValue = indicesOptions;
			return Self;
		}

		public MlPutDatafeedRequestDescriptor IndicesOptions(IndicesOptionsDescriptor descriptor)
		{
			IndicesOptionsValue = null;
			IndicesOptionsDescriptorAction = null;
			IndicesOptionsDescriptor = descriptor;
			return Self;
		}

		public MlPutDatafeedRequestDescriptor IndicesOptions(Action<IndicesOptionsDescriptor> configure)
		{
			IndicesOptionsValue = null;
			IndicesOptionsDescriptor = null;
			IndicesOptionsDescriptorAction = configure;
			return Self;
		}

		public MlPutDatafeedRequestDescriptor JobId(Elastic.Clients.Elasticsearch.Id? jobId)
		{
			JobIdValue = jobId;
			return Self;
		}

		public MlPutDatafeedRequestDescriptor MaxEmptySearches(int? maxEmptySearches)
		{
			MaxEmptySearchesValue = maxEmptySearches;
			return Self;
		}

		public MlPutDatafeedRequestDescriptor QueryDelay(Elastic.Clients.Elasticsearch.Duration? queryDelay)
		{
			QueryDelayValue = queryDelay;
			return Self;
		}

		public MlPutDatafeedRequestDescriptor RuntimeMappings(Func<FluentDictionary<Elastic.Clients.Elasticsearch.Field, IEnumerable<Elastic.Clients.Elasticsearch.Mapping.RuntimeField>>, FluentDictionary<Elastic.Clients.Elasticsearch.Field, IEnumerable<Elastic.Clients.Elasticsearch.Mapping.RuntimeField>>> selector)
		{
			RuntimeMappingsValue = selector?.Invoke(new FluentDictionary<Elastic.Clients.Elasticsearch.Field, IEnumerable<Elastic.Clients.Elasticsearch.Mapping.RuntimeField>>());
			return Self;
		}

		public MlPutDatafeedRequestDescriptor ScriptFields(Func<FluentDictionary<string, Elastic.Clients.Elasticsearch.ScriptField>, FluentDictionary<string, Elastic.Clients.Elasticsearch.ScriptField>> selector)
		{
			ScriptFieldsValue = selector?.Invoke(new FluentDictionary<string, Elastic.Clients.Elasticsearch.ScriptField>());
			return Self;
		}

		public MlPutDatafeedRequestDescriptor ScrollSize(int? scrollSize)
		{
			ScrollSizeValue = scrollSize;
			return Self;
		}

		protected override void Serialize(Utf8JsonWriter writer, JsonSerializerOptions options, IElasticsearchClientSettings settings)
		{
			writer.WriteStartObject();
			if (QueryDescriptor is not null)
			{
				writer.WritePropertyName("query");
				JsonSerializer.Serialize(writer, QueryDescriptor, options);
			}
			else if (QueryDescriptorAction is not null)
			{
				writer.WritePropertyName("query");
				JsonSerializer.Serialize(writer, new QueryDsl.QueryContainerDescriptor(QueryDescriptorAction), options);
			}
			else if (QueryValue is not null)
			{
				writer.WritePropertyName("query");
				JsonSerializer.Serialize(writer, QueryValue, options);
			}

			if (AggregationsValue is not null)
			{
				writer.WritePropertyName("aggregations");
				JsonSerializer.Serialize(writer, AggregationsValue, options);
			}

			if (ChunkingConfigDescriptor is not null)
			{
				writer.WritePropertyName("chunking_config");
				JsonSerializer.Serialize(writer, ChunkingConfigDescriptor, options);
			}
			else if (ChunkingConfigDescriptorAction is not null)
			{
				writer.WritePropertyName("chunking_config");
				JsonSerializer.Serialize(writer, new ChunkingConfigDescriptor(ChunkingConfigDescriptorAction), options);
			}
			else if (ChunkingConfigValue is not null)
			{
				writer.WritePropertyName("chunking_config");
				JsonSerializer.Serialize(writer, ChunkingConfigValue, options);
			}

			if (DelayedDataCheckConfigDescriptor is not null)
			{
				writer.WritePropertyName("delayed_data_check_config");
				JsonSerializer.Serialize(writer, DelayedDataCheckConfigDescriptor, options);
			}
			else if (DelayedDataCheckConfigDescriptorAction is not null)
			{
				writer.WritePropertyName("delayed_data_check_config");
				JsonSerializer.Serialize(writer, new DelayedDataCheckConfigDescriptor(DelayedDataCheckConfigDescriptorAction), options);
			}
			else if (DelayedDataCheckConfigValue is not null)
			{
				writer.WritePropertyName("delayed_data_check_config");
				JsonSerializer.Serialize(writer, DelayedDataCheckConfigValue, options);
			}

			if (FrequencyValue is not null)
			{
				writer.WritePropertyName("frequency");
				JsonSerializer.Serialize(writer, FrequencyValue, options);
			}

			if (HeadersValue is not null)
			{
				writer.WritePropertyName("headers");
				JsonSerializer.Serialize(writer, HeadersValue, options);
			}

			if (IndicesValue is not null)
			{
				writer.WritePropertyName("indices");
				JsonSerializer.Serialize(writer, IndicesValue, options);
			}

			if (IndicesOptionsDescriptor is not null)
			{
				writer.WritePropertyName("indices_options");
				JsonSerializer.Serialize(writer, IndicesOptionsDescriptor, options);
			}
			else if (IndicesOptionsDescriptorAction is not null)
			{
				writer.WritePropertyName("indices_options");
				JsonSerializer.Serialize(writer, new IndicesOptionsDescriptor(IndicesOptionsDescriptorAction), options);
			}
			else if (IndicesOptionsValue is not null)
			{
				writer.WritePropertyName("indices_options");
				JsonSerializer.Serialize(writer, IndicesOptionsValue, options);
			}

			if (JobIdValue is not null)
			{
				writer.WritePropertyName("job_id");
				JsonSerializer.Serialize(writer, JobIdValue, options);
			}

			if (MaxEmptySearchesValue.HasValue)
			{
				writer.WritePropertyName("max_empty_searches");
				writer.WriteNumberValue(MaxEmptySearchesValue.Value);
			}

			if (QueryDelayValue is not null)
			{
				writer.WritePropertyName("query_delay");
				JsonSerializer.Serialize(writer, QueryDelayValue, options);
			}

			if (RuntimeMappingsValue is not null)
			{
				writer.WritePropertyName("runtime_mappings");
				JsonSerializer.Serialize(writer, RuntimeMappingsValue, options);
			}

			if (ScriptFieldsValue is not null)
			{
				writer.WritePropertyName("script_fields");
				JsonSerializer.Serialize(writer, ScriptFieldsValue, options);
			}

			if (ScrollSizeValue.HasValue)
			{
				writer.WritePropertyName("scroll_size");
				writer.WriteNumberValue(ScrollSizeValue.Value);
			}

			writer.WriteEndObject();
		}
	}
}